package me.lc.util.offer;

import me.lc.FunPeaceActivity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class OfferHelper {
	private static IOffer offerClient = new DianJoyOfferUtil();

	public static void init(final Context context) {
		FunPeaceActivity.Instance.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				offerClient.init(context);
			}
		});
	}

	public static void updateCoins(final Context context) {
		FunPeaceActivity.Instance.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				offerClient.updateCoins(context);
			}
		});
	}

	public static void dispose(final Context context) {
		FunPeaceActivity.Instance.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				offerClient.dispose(context);
			}
		});
	}

	/**
	 * 显示offfer界面
	 * 
	 * @param context
	 * @param replaceTip
	 *            不显示offer的情况下的替换文�?
	 * 
	 * @param confimTip
	 *            确认提示的文本，为null则不做提�?
	 */
	public static void showOffer(final Context context,
			final String replaceTip, final String confimTip) {
		FunPeaceActivity.Instance.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				if (confimTip != null) {
					AlertDialog alertDialog = new AlertDialog.Builder(
							FunPeaceActivity.Instance)
							.setTitle("提示")
							.setMessage(confimTip)
							.setPositiveButton("免费赚取",
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											offerClient.showOffer(context);
										}
									})
							.setNegativeButton("取消",
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											return;
										}
									}).setCancelable(false).create();
					alertDialog.show();
				} else {
					offerClient.showOffer(context);
				}
			}
		});
	}
}
